{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--- cwd: /visrag/root/myconda/VisRAG\n"
     ]
    },
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'tools'",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mModuleNotFoundError\u001B[0m                       Traceback (most recent call last)",
      "Cell \u001B[0;32mIn[9], line 11\u001B[0m\n\u001B[1;32m      8\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m parent_dir \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;129;01min\u001B[39;00m sys\u001B[38;5;241m.\u001B[39mpath:\n\u001B[1;32m      9\u001B[0m     sys\u001B[38;5;241m.\u001B[39mpath\u001B[38;5;241m.\u001B[39minsert(\u001B[38;5;241m0\u001B[39m, parent_dir)\n\u001B[0;32m---> 11\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mtools\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mchange_cwd_to_main\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m change_cwd_to_main\n",
      "\u001B[0;31mModuleNotFoundError\u001B[0m: No module named 'tools'"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "import os\n",
    "\n",
    "# 将父级路径加入到 Python 的搜索路径中\n",
    "cwd = os.getcwd()\n",
    "print(f'--- cwd: {cwd}')\n",
    "parent_dir = os.path.abspath(os.path.join(cwd, '..'))\n",
    "if parent_dir not in sys.path:\n",
    "    sys.path.insert(0, parent_dir)\n",
    "\n",
    "from tools.change_cwd_to_main import change_cwd_to_main\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'tools'",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mModuleNotFoundError\u001B[0m                       Traceback (most recent call last)",
      "Cell \u001B[0;32mIn[3], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mtools\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mchange_cwd_to_main\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m change_cwd_to_main\n\u001B[1;32m      2\u001B[0m change_cwd_to_main()\n\u001B[1;32m      5\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;21;01mnumpy\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m \u001B[38;5;21;01mnp\u001B[39;00m\n",
      "\u001B[0;31mModuleNotFoundError\u001B[0m: No module named 'tools'"
     ]
    }
   ],
   "source": [
    "change_cwd_to_main()\n",
    "\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "# import plotly.express as px\n",
    "import matplotlib.pyplot as plt\n",
    "import plotly.express as px\n",
    "\n",
    "\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import mean_absolute_percentage_error\n",
    "\n",
    "\n",
    "# dtype = {\n",
    "#     'Price': 'float'           # 将 Price 列转换为浮点数\n",
    "# }\n",
    "columns_to_convert = ['Price', 'High', 'Low', 'Open']\n",
    "df = pd.read_csv('data/Gold Futures Historical Data_20130101-20241112.csv', converters={col: lambda x: float(x.replace(',', '')) for col in columns_to_convert}, parse_dates=['Date'])\n",
    "\n",
    "\n",
    "df\n",
    "df['Price']\n",
    "df.dtypes\n",
    "\n",
    "df['Price'].describe()\n",
    "df['Price'].describe(include='all')\n",
    "\n",
    "summary = df.describe()\n",
    "print(summary)\n",
    "\n",
    "df.drop(['Vol.', 'Change %'], axis=1, inplace=True)\n",
    "\n",
    "\n",
    "df = df.sort_values(by=['Date'], ascending=False)\n",
    "df.reset_index(drop=True, inplace=True)\n",
    "\n",
    "df.head()\n",
    "\n",
    "df.duplicated().sum()\n",
    "\n",
    "df.isnull().sum().sum()\n",
    "\n",
    "\n",
    "fig = px.line(y=df.Price, x=df.Date)\n",
    "fig.update_traces(line_color='black')\n",
    "fig.update_layout(xaxis_title=\"Date\",\n",
    "                  yaxis_title=\"Scaled Price\",\n",
    "                  title={'text': \"Gold Price History Data\", 'y':0.95, 'x':0.5, 'xanchor':'center', 'yanchor':'top'},\n",
    "                  plot_bgcolor='rgba(255,223,0,0.8)')\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}